<template>
  <div class="app-container">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-tab-pane label="镜像环境" name="mirror">
        <el-table :data="list" border fit highlight-current-row stripe>
          <el-table-column type="index">
          </el-table-column>
          <el-table-column label="thirdPartyId">
            <template slot-scope="{ row }">
              <span @click="copy(row.thirdPartyId)">{{ row.thirdPartyId }}</span>
            </template>
          </el-table-column>
          <el-table-column label="prodId" show-overflow-tooltip>
            <template slot-scope="{ row }">
              <span class="link-type">
                <a target="_blank" :href="row.svnPath">{{ row.prodId }}</a>
              </span>
            </template>
          </el-table-column>
          <el-table-column label="车厂名" show-overflow-tooltip>
            <template slot-scope="{ row }">
              <span @click="copy(row.tspName)">{{ row.tspName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="TAG" show-overflow-tooltip>
            <template slot-scope="{ row }">
              <span @click="copy(row.tag)">{{ row.tag }}</span>
            </template>
          </el-table-column>
          <el-table-column label="OAuth Url" show-overflow-tooltip>
            <template slot-scope="{ row }">
              <span @click="copy(row.oauthUrl)">{{ row.oauthUrl }}</span>
            </template>
          </el-table-column>
          <el-table-column label="Service Url" show-overflow-tooltip>
            <template slot-scope="{ row }">
              <span @click="copy(row.serviceUrl)">{{ row.serviceUrl }}</span>
            </template>
          </el-table-column>
          <el-table-column label="ClientId" show-overflow-tooltip>
            <template slot-scope="{ row }">
              <span @click="copy(row.clientId)">{{ row.clientId }}</span>
            </template>
          </el-table-column>
          <el-table-column label="Client Secret" show-overflow-tooltip>
            <template slot-scope="{ row }">
              <span @click="copy(row.clientSecret)">{{ row.clientSecret }}</span>
            </template>
          </el-table-column>
          <el-table-column label="Redirect Url" show-overflow-tooltip>
            <template slot-scope="{ row }">
              <span @click="copy(row.redirectUrl)">{{ row.redirectUrl }}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="生产环境" name="prod">
        <el-table :data="list" border fit highlight-current-row stripe>
          <el-table-column type="index">
          </el-table-column>
          <el-table-column label="thirdPartyId">
            <template slot-scope="{ row }">
              <span @click="copy(row.thirdPartyId)">{{ row.thirdPartyId }}</span>
            </template>
          </el-table-column>
          <el-table-column label="prodId" show-overflow-tooltip>
            <template slot-scope="{ row }">
              <span class="link-type">
                <a target="_blank" :href="row.svnPath">{{ row.prodId }}</a>
              </span>
            </template>
          </el-table-column>
          <el-table-column label="车厂名" show-overflow-tooltip>
            <template slot-scope="{ row }">
              <span @click="copy(row.tspName)">{{ row.tspName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="TAG" show-overflow-tooltip>
            <template slot-scope="{ row }">
              <span @click="copy(row.tag)">{{ row.tag }}</span>
            </template>
          </el-table-column>
          <el-table-column label="OAuth Url" show-overflow-tooltip>
            <template slot-scope="{ row }">
              <span @click="copy(row.oauthUrl)">{{ row.oauthUrl }}</span>
            </template>
          </el-table-column>
          <el-table-column label="Service Url" show-overflow-tooltip>
            <template slot-scope="{ row }">
              <span @click="copy(row.serviceUrl)">{{ row.serviceUrl }}</span>
            </template>
          </el-table-column>
          <el-table-column label="ClientId" show-overflow-tooltip>
            <template slot-scope="{ row }">
              <span @click="copy(row.clientId)">{{ row.clientId }}</span>
            </template>
          </el-table-column>
          <el-table-column label="Client Secret" show-overflow-tooltip>
            <template slot-scope="{ row }">
              <span @click="copy(row.clientSecret)">{{ row.clientSecret }}</span>
            </template>
          </el-table-column>
          <el-table-column label="Redirect Url" show-overflow-tooltip>
            <template slot-scope="{ row }">
              <span @click="copy(row.redirectUrl)">{{ row.redirectUrl }}</span>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import request from '@/utils/request'

export default {
  data() {
    return {
      activeName: 'mirror',
      list: []
    }
  },
  created() {
    this.getTspsList(this.activeName)
  },
  methods: {
    copy(rt) {
      this.$copyText(rt).then(e => {
        this.$notify({
          title: '成功',
          message: '复制成功!',
          type: 'success'
        })
      }, e => {
        this.$notify.error({
          title: '失败',
          message: '复制RT失败!'
        })
      })
    },
    getTspsList(env = 'mirror') {
      this.list = []
      request({
        url: `/tspmock/table/t_tsps`,
        method: 'get',
        params: { env }
      }).then(configs => {
        this.list.push(...configs)
      })
    },
    handleClick(tab) {
      this.getTspsList(tab.name)
    }
  }
}
</script>

<style scoped>
  .edit-input {
    padding-right: 100px;
  }

  .cancel-btn {
    position: absolute;
    right: 15px;
    top: 10px;
  }
</style>
